/**
 * 
 */
package will.icecoffe.core;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import will.icecoffe.core.DataAccessException;
import will.icecoffe.core.DataAccessObject;
import will.icecoffe.core.Finder;
import will.icecoffe.utils.Page;

/**
 * @author will
 * 
 */
@Component("basicSQLFinder")
public class BasicSQLFinder<T> extends Finder<T> {

	@Override
	public List<T> find(Object... args) throws DataAccessException {
		
		if (null == args || 0 == args.length || !(args[0] instanceof String)) {
			throw new QueryParametersException("查询命名或参数不能为空！");
		}

		Object[] params = new Object[args.length - 1];
		params = Arrays.copyOfRange(args, 1, args.length);
		
		return (List<T>) dao.executeNamedSQLQuery((String) args[0], params);

	}

	@Override
	public Page<T> find(int page, int rows, Object... args)
			throws DataAccessException {

		if (null == args || 0 == args.length || !(args[0] instanceof String)) {
			throw new QueryParametersException("查询命名或参数不能为空！");
		}

		Object[] params = new Object[args.length - 1];
		params = Arrays.copyOfRange(args, 1, args.length);
		
		return (Page<T>) dao.findBasedPageNative(page, rows, (String) args[0], params);

	}

}
